package com.jdk18.digui;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by xuyiwei on 2018/7/11.
 */
public class DiguiTest {

    public static List<TreeList> treeListList = new ArrayList<>();

    static {
        treeListList.add(new TreeList(1L,0L,"根节点"));
        treeListList.add(new TreeList(2L,1L,"子节点"));
        treeListList.add(new TreeList(3L,2L,"子节点1"));
        treeListList.add(new TreeList(4L,3L,"子节点2"));
        treeListList.add(new TreeList(5L,4L,"子节点3"));
    }


    public static List<TreeList> digui(Long id,TreeList treeList){
        List<TreeList> son = treeListList.stream().filter(fn->fn.getParent_id().equals(id)).collect(Collectors.toList());
        for(TreeList list : son){
            list.setSonTreeList(digui(list.getId(),list));
        }
        return son;
    }

    public static void main(String[] args) {
        List<TreeList> arr = DiguiTest.treeListList;
        TreeList list = new TreeList(1L,0L,"根节点");
        List<TreeList> lists = digui(0L,list);
        System.out.println(lists);
    }
}
